<?php

namespace app\api\controller;

use app\common\business\User as userBn;
use app\common\business\Integral as integralBn;
use think\Validate;
use app\common\redis\db0\Userinfo as redisBn;
class Integral extends \app\common\controller\HomeBase {

    /**
     * 商城商品列表
     */
    public function integrallist() {
        try {
            $params = input();
            $data = integralBn::integrallist($params);
            $sys = F('System');
            $data['integral_logo']=config('staticResourceHost').$sys['integral_logo'];
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 兑换商品
     * 
     */
    public function exchangegoods() {
        try {
            $user_id = $this->_validLogin();

            $params = input();
            $validate = Validate('Integral');
            $params = $validate->scene('add')->check($params);
            if (!$params) {
                exception($validate->getError(), 10000003);
            }
            $params['user_id']=$user_id;
            $data = integralBn::exchangegoods($params);
            $this->_echoSuccessMessage('兑换成功', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
    /**
     * 兑换商品
     *
     */
    public function usergoods() {
        try {
            $user_id = $this->_validLogin();


            $params['user_id']=$user_id;
            $data = integralBn::usergoods($params);
            $this->_echoSuccessMessage('兑换成功', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }


}
